package com.example.smartwaterapi.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 微信配置类
 * 配置微信公众号和小程序相关服务
 */
@Configuration
public class WechatConfig {

    @Value("${wechat.official.appid:}")
    private String officialAccountAppId;

    @Value("${wechat.official.secret:}")
    private String officialAccountSecret;

    @Value("${wechat.miniapp.app-id:}")
    private String miniprogramAppId;

    @Value("${wechat.miniapp.secret:}")
    private String miniprogramSecret;

    @Value("${wechat.official.template-id:}")
    private String templateId;

    // Getter方法
    public String getAppid() {
        return officialAccountAppId;
    }

    public String getAppSecret() {
        return officialAccountSecret;
    }

    public String getMiniAppId() {
        return miniprogramAppId;
    }

    public String getTemplateId() {
        return templateId;
    }

    /**
     * 配置微信公众号服务
     */
    @Bean
    public WxMpService wxMpService() {
        WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
        config.setAppId(officialAccountAppId);
        config.setSecret(officialAccountSecret);
        
        WxMpServiceImpl wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(config);
        
        return wxMpService;
    }

    /**
     * 配置微信小程序服务
     */
    @Bean
    public WxMaService wxMaService() {
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(miniprogramAppId);
        config.setSecret(miniprogramSecret);
        
        WxMaServiceImpl wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(config);
        
        return wxMaService;
    }
} 
